import service from "../../utils/request.ts";
import type {TreeKey} from "element-plus";

/**
 * 分页查询租户信息列表
 * @param payload 分页参数
 */
export const getRolePage = (payload)=> {
    return service({
        url: "/role/pageRoleList",
        method: 'POST',
        data: payload
    })
}



/**
 * 分页查询租户信息列表
 */
export const importRole = (file)=> {
    return service({
        url: `/role/import`,
        method: 'Post',
        data: file
    })
}

/**
 *  新增修改角色信息
 */
export const addOrUpdateRole = (role,operation)=> {
    return service({
        url: `/role/addOrUpdate/${operation}`,
        method: 'Post',
        data: role
    })
}

/**
 * 根据id查询角色信息
 */
export const getRoleInfoById = (id)=> {
    return service({
        url: `/role/${id}`,
        method: 'get',
        data: null
    })
}

/**
 * 根据id删除角色信息
 */
export const deleteRoleById = (id)=> {
    return service({
        url: `/role/${id}`,
        method: 'delete',
        data: null
    })
}

/**
 * 批量删除id
 */
export const deleteRoleByIdBatch = (ids: number[])=> {
    return service({
        url: `/role/deleteBatch`,
        method: 'delete',
        data: ids
    })
}
/**
 * 获取可授权的菜单树
 * @param roleId
 */
export const grantMenuTree=(roleId:number)=>{
    return service({
        url: `/role/getRoleGrantTree`,
        method: 'get',
        params:{roleId},
        data: null
    })
}

/**
 * 修改授权
 * @param roleId
 * @param checkedKeys
 */
export const updateGrate= (roleId: number, checkedKeys:number[])=>{
    return service({
        url: `/role/grant/${roleId}`,
        method: 'post',
        data: checkedKeys
    })
}



export const getRoles=()=>{
    return service({
        url: `/role/list`,
        method: 'get',
        data: null
    })
}